判斷圖片是彩色還是黑白
private int CountWhite()
{
Bitmap bmp = (Bitmap)this.pictureBox1.Image;
Color color;
int iTotal = bmp.Height * bmp.Width, count = 0;
for (int x = 0; x < bmp.Width - 1; x )
{
for (int y = 0; y < bmp.Height - 1; y )
{
color = bmp.GetPixel(x, y);
if (color.R == 255 && color.G == 255 && color.B == 255)
{
count ;
}
}
}
return count;
}
private int CountBlack()
{
Bitmap bmp = (Bitmap)this.pictureBox1.Image;
Color color;
int iTotal = bmp.Height * bmp.Width, count = 0;
for (int x = 0; x < bmp.Width - 1; x )
{
for (int y = 0; y < bmp.Height - 1; y )
{
color = bmp.GetPixel(x, y);
if (color.R == 0 && color.G == 0 && color.B == 0)
{
count ;
}
}
}
return count;
}
评论